﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Content.Master" Inherits="System.Web.Mvc.ViewPage<MethodWorx.CMS.UI.Areas.Dashboard.Models.TemplateGalleryModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <style>
        div.template
        {
            padding:5px;
            border-bottom:1px dotted silver;
            cursor:pointer;
        }
        div.template:hover
        {
            background-color:#BEEBFF;
        }
    </style>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#category").change(function () {
                $.getJSON("<%=Url.Content("~/TemplateGallery/GetTemplates")%>", { category: $(this).val() }, function (obj) {
                    var html = "";
                    for (var i = 0; i < obj.length; i++) {
                        html += "<div class=\"template\" name=\"" + obj[i].Filename + "\"><table><tr><td style=\"width:100%\"><p><strong>" + obj[i].Name + "</strong></p><p><em>Author: " + obj[i].Author + "</em></p></td><td style=\"width:50px\"><img name=\"" + obj[i].Filename + "\" class=\"previewButton\" src=\"<%=Url.Content("~/images/icons/magnifier.png")%>\" title=\"Preview Template\"/></td></table></div>";
                    }
                    $("#templates").html(html);

                    $(".template").dblclick(function () {
                        if (confirm("Are you sure you want to install this template/add on?")) {
                            //
                            //
                            var name = $(this).attr("name");
                            window.parent.parent.openDialog("<%=Url.Content("~/Dashboard/TemplateGallery")%>/Install?filename=" + $(this).attr("name"), "Install Template");
                        }
                    });

                    $(".previewButton").click(function () {
                        MethodWorx.CMS.showPreview("<%=Url.Content("~/Dashboard/TemplateGallery")%>/Preview?filename=" + $(this).attr("name"));
                    });
                });


            });

            $("#cancelButton").click(function () {
                window.parent.closeDialog();
            });
        });
    </script>

    <%if(this.Model.DialogMode)
          {%>
          <div class="formItem">
            Please double click the template you would like to install.
            </div>
        <%
          }%>
    <div class="formItem">
        <label>Template Category:</label>
        <%=Html.DropDownList("category", Model.GetCategorySelectList(), "-- Select Category --")%>
        </div>
        <%
            if (!this.Model.DialogMode)
            {%>
        <div style="overflow:auto; border:1px solid silver; margin:10px;height:180px" id="templates">
        </div>
        <%
            }
            else{%>
            <div style="overflow:auto; border:1px solid silver; margin:10px;height:270px" id="templates">
        </div>
        <div class="formItem">
            <button type="button" id="cancelButton">Cancel</button>
        </div>
          <%
            }
%>
    </div>

</asp:Content>
